﻿namespace BusinessApplication1
{
    using System.Windows;
    using System.Windows.Controls;
    using System.Windows.Navigation;
    using BusinessApplication1.LoginUI;
    using System;
    using MenuControl;
    using BusinessApplication1.Views;
    using BusinessApplication1.Views.Task;
    using BusinessApplication1.Views.Login;
    using BusinessApplication1.Views.UserManagement;

    /// <summary>
    /// <see cref="UserControl"/> class providing the main UI for the application.
    /// </summary>
    
    public partial class MainPage : UserControl
    {
        /// <summary>
        /// Creates a new <see cref="MainPage"/> instance.
        /// </summary>
        
        public MainPage()
        {
            InitializeComponent();
            

        }

        private void Quit(object sender, RoutedEventArgs e)
        {
            ChildWindow Close = new ApplicationQuit();
            Close.Closed += new EventHandler(logout);
            Close.Show(); 
        }

        void logout(object sender, EventArgs e)
        {
            ChildWindow lw = (ChildWindow)sender;

            if (lw.DialogResult == true)
            {
                this.ContentFrame.Navigate(new Uri("/Authorization", UriKind.RelativeOrAbsolute));
            }
        }


        /// <summary>
        /// After the Frame navigates, ensure the <see cref="HyperlinkButton"/> representing the current page is selected
        /// </summary>
        private void ContentFrame_Navigated(object sender, NavigationEventArgs e)
        {

        }



        private void ContentFrame_NavigationFailed(object sender, NavigationFailedEventArgs e)
        {
            e.Handled = true;
            ErrorWindow.CreateNew(e.Exception);
        }
        private void MenuItem_Click(object sender, RoutedEventArgs e)
        {
            MenuControl.MenuItem mi = sender as MenuControl.MenuItem;
            this.ContentFrame.Navigate(new Uri(mi.Tag.ToString(), UriKind.RelativeOrAbsolute));

        }

        private void button1_Click(object sender, RoutedEventArgs e)
        {
            MenuControl.MenuItem mi = sender as MenuControl.MenuItem;
            ChildWindow dialog;
            switch (mi.Tag.ToString())
            {
                case "/Task/AddNewProject": 
                    dialog = new AddNewProject("Создание проекта");
                    break;
                case "/Task/AddNewTask":
                    dialog = new AddNewTask("Создание задачи");
                    break;
 //               case "/Login/ApplicationQuit":
   //                 dialog = new ApplicationQuit();
     //               break;
                case "/UserManagement/UserCreate":
                    dialog = new UserCreate();
                    break;
                case "/UserManagement/ChooseForEdit":
                    dialog = new ChooseForEdit();
                    break;
                case "/UserManagement/UserDelete":
                    dialog = new UserDelete();
                    break;
                case "/UserManagement/UserBlocking":
                    dialog = new UserBlocking();
                    break;
                case "/UserManagement/UserUnBlocking":
                    dialog = new UserUnBlocking();
                    break;
                case "/UserManagement/PasswordUserEdit":
                    dialog = new PasswordUserEdit();
                    break;
                case "/UserManagement/PasswordEdit":
                    dialog = new PasswordEdit();
                    break;
                case "/Task/ChangeTimeBegin":
                    dialog = new ChangeTimeBegin();
                    break;
                case "/Task/ChangeTimeEnd":
                    dialog = new ChangeTimeEnd();
                    break;
                default: 
                    dialog = new ErrorWindow("Ошибка построения дочерней страницы","Проверьте наличие case в файле MainPage.xaml.cs");
                    break;
                    
            }
            
            dialog.Closed += (s, ea) =>
            {
                if (dialog.DialogResult == true)
                {
                   

                }
                else if (dialog.DialogResult == false)
                {
                   
                }
                else
                {
                    
                }
            };
            dialog.Show();
        }


        private void LoginStatus_Loaded(object sender, RoutedEventArgs e)
        {


        }

        private void hyperlinkButton1_Click(object sender, RoutedEventArgs e)
        {
            ChildWindow dialog = new ApplicationQuit();
            dialog.Closed += (s, ea) =>
            {
                if (dialog.DialogResult == true)
                {
                 
                }
                else if (dialog.DialogResult == false)
                {

                }
                else
                {
                    
                }
            };
            dialog.Show();
            
        }


    }
}